/**
 * 中间件, 判断是否存在 . git 文件夹
 */

import type { Request, Response, NextFunction } from 'express';
import fs from 'fs';
import path from 'path';

export function checkEsistGit(_req: Request, res: Response, next: NextFunction) {
	const readDirRes = fs.readdirSync(path.resolve(__dirname, '../gitProject/commitProject'));
	const isExist = readDirRes.includes('.git');

	if (!isExist) {
		return res.json(formatResJson({ code: 'Fail', msg: '请先调用 /init 初始化配置git仓库' }));
	}

	return next();
}
